package com.ruoyi.web.controller.mdm;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mdm.domain.SkuMergeMaster;
import com.ruoyi.mdm.service.ISkuMergeMasterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * skum管理Controller
 *
 * @author shiseido
 * @date 2025-03-01
 */
@RestController
@RequestMapping("/mdm/skuMergeMaster")
public class SkuMergeMasterController extends BaseController {
    @Autowired
    private ISkuMergeMasterService skuMergeMasterService;

    /**
     * 查询skum管理列表
     */
    @ApiOperation("查询skum管理列表")
    @GetMapping("/list")
    public TableDataInfo list(SkuMergeMaster skuMergeMaster) {
        startPage();
        List<SkuMergeMaster> list = skuMergeMasterService.selectSkuMergeMasterList(skuMergeMaster);
        return getDataTable(list);
    }

    /**
     * 导出skum管理列表
     */
    @ApiOperation("导出skum管理列表")
    @PreAuthorize("@ss.hasPermi('mdm:skuMergeMaster:export')")
    @Log(title = "SKUM管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkuMergeMaster skuMergeMaster) {
        List<SkuMergeMaster> list = skuMergeMasterService.selectSkuMergeMasterList(skuMergeMaster);
        ExcelUtil<SkuMergeMaster> util = new ExcelUtil<SkuMergeMaster>(SkuMergeMaster.class);
        util.exportExcel(response, list, "skum管理数据");
    }

    /**
     * 获取skum管理详细信息
     */
    @ApiOperation("获取skum管理详细信息")
    @PreAuthorize("@ss.hasPermi('mdm:skuMergeMaster:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(skuMergeMasterService.selectSkuMergeMasterById(id));
    }

    /**
     * 新增skum管理
     */
    @ApiOperation("新增skum管理")
    @PreAuthorize("@ss.hasPermi('mdm:skuMergeMaster:add')")
    @Log(title = "SKUM管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkuMergeMaster skuMergeMaster) {

        // 来源 默认02:手动
        skuMergeMaster.setSkumSource("02");

        skuMergeMaster.setCreateBy(getUsername());
        skuMergeMaster.setUpdateBy(getUsername());
        return toAjax(skuMergeMasterService.insertSkuMergeMaster(skuMergeMaster));
    }

    /**
     * 修改skum管理
     */
    @ApiOperation("修改skum管理")
    @PreAuthorize("@ss.hasPermi('mdm:skuMergeMaster:edit')")
    @Log(title = "SKUM管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkuMergeMaster skuMergeMaster) {
        skuMergeMaster.setCreateBy(getUsername());
        skuMergeMaster.setUpdateBy(getUsername());
        return toAjax(skuMergeMasterService.updateSkuMergeMaster(skuMergeMaster));
    }

    /**
     * 删除skum管理
     */
    @ApiOperation("删除skum管理")
    @PreAuthorize("@ss.hasPermi('mdm:skuMergeMaster:remove')")
    @Log(title = "SKUM管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(skuMergeMasterService.deleteSkuMergeMasterByIds(ids));
    }
}
